﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LTP.Common;
using System.Web.UI.HtmlControls;

namespace CJJCH.Web.Controls
{
    public partial class Top1 : System.Web.UI.UserControl
    {
        CJJCH.BLL.T_PRD_Book bll_book = new BLL.T_PRD_Book();
        CJJCH.BLL.T_NET_MenuThird bll_third = new BLL.T_NET_MenuThird();
        CJJCH.BLL.T_NET_MenuSecond bll_second = new BLL.T_NET_MenuSecond();
        CJJCH.BLL.T_NET_MenuFirst bll_first = new BLL.T_NET_MenuFirst();
        CJJCH.BLL.T_NET_MenuSecond bll_menusecond = new BLL.T_NET_MenuSecond();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitMenu();
                BookBinding();
            }
        }
        private int _iIndex;

        public int IIndex
        {
            get { return _iIndex; }
            set { _iIndex = value; }
        }
        private int _firstId;

        public int FirstId
        {
            get { return _firstId; }
            set { _firstId = value; }
        }

        private int _secondId;

        public int SecondId
        {
            get { return _secondId; }
            set { _secondId = value; }
        }

        private int _thirdId;

        public int ThirdId
        {
            get { return _thirdId; }
            set { _thirdId = value; }
        }

        private string _keyword;

        public string Keyword
        {
            get { return _keyword; }
            set { _keyword = value; }
        }
        private string _typename;

        public string Typename
        {
            get { return _typename; }
            set { _typename = value; }
        }

        private void InitMenu()
        {
            switch (this.IIndex)
            {
                case 0:
                    this.menu1.Attributes.Add("class", "MenuCur");
                    break;
                case 1:
                    this.menu2.Attributes.Add("class", "MenuCur");
                    break;
                case 2:
                    this.menu3.Attributes.Add("class", "MenuCur");
                    break;
                case 3:
                    this.menu4.Attributes.Add("class", "MenuCur");
                    break;
                case 4:
                    this.menu5.Attributes.Add("class", "MenuCur");
                    break;
                case 5:
                    this.menu6.Attributes.Add("class", "MenuCur");
                    break;
                case 6:
                    this.menu7.Attributes.Add("class", "MenuCur");
                    break;
                case 7:
                    this.menu8.Attributes.Add("class", "MenuCur");
                    break;
                case 8:
                    this.menu9.Attributes.Add("class", "MenuCur");
                    break;
                default:
                    break;
            }



            if (!string.IsNullOrEmpty(Request.QueryString["keyword"]))
            {
                txtSearch.Text = Request.QueryString["keyword"].ToString();

            }
            if (Request.QueryString["firstid"] != null && LTP.Common.CheckInput.CheckDigit(Request.QueryString["firstid"]))
            {
                FirstId = Convert.ToInt32(Request.QueryString["firstid"]);

            }
            if (Request.QueryString["secondid"] != null && LTP.Common.CheckInput.CheckDigit(Request.QueryString["secondid"]))
            {
                SecondId = Convert.ToInt32(Request.QueryString["secondid"]);

            }
            if (Request.QueryString["thirdid"] != null && LTP.Common.CheckInput.CheckDigit(Request.QueryString["thirdid"]))
            {
                ThirdId = Convert.ToInt32(Request.QueryString["thirdid"]);

            }
            if (!string.IsNullOrEmpty(Request.QueryString["typename"]))
            {
                lblType1.Text = Request.QueryString["typeName"].Trim();

            }
        }

        private void BookBinding()
        {
            this.lnkBookShop.NavigateUrl = LTP.Common.ConfigHelper.GetConfigString("BookShopWeb") + "Index.aspx";
            this.lnkBook.NavigateUrl = LTP.Common.ConfigHelper.GetConfigString("BookShopWeb") + "Index.aspx";
            IList<CJJCH.Model.T_PRD_Book> book = new List<CJJCH.Model.T_PRD_Book>();
            book = bll_book.GetBookTop(5);
            rptBookNews.DataSource = book;
            rptBookNews.DataBind();
            IList<CJJCH.Model.T_NET_MenuFirst> firstList = new List<CJJCH.Model.T_NET_MenuFirst>();
            firstList = bll_first.GetMenuFirstType(9);
            this.rptMenu.DataSource = firstList;
            this.rptMenu.DataBind();
        }
        /// <summary>
        /// 最新书讯
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptBookNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                ((HyperLink)e.Item.FindControl("lnkBook")).Text = LTP.Common.StringClass.GetENString(((CJJCH.Model.T_PRD_Book)e.Item.DataItem).BookName.Trim(), 16);
                ((HyperLink)e.Item.FindControl("lnkBook")).ToolTip = ((CJJCH.Model.T_PRD_Book)e.Item.DataItem).BookName.Trim();
                ((HyperLink)e.Item.FindControl("lnkBook")).NavigateUrl = ConfigHelper.GetConfigString("BookShopWeb") + "BookDetail.aspx?ID=" + LTP.Common.StringClass.EncodeUrl(((CJJCH.Model.T_PRD_Book)e.Item.DataItem).ID.ToString());
            }
        }

        protected void rptMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            ((HyperLink)e.Item.FindControl("lnkMenu")).Text = ((CJJCH.Model.T_NET_MenuFirst)e.Item.DataItem).MenuName;

            if (((CJJCH.Model.T_NET_MenuFirst)e.Item.DataItem).MenuName.Length > 9)
            {
                ((HyperLink)e.Item.FindControl("lnkMenu")).Style.Add("font-size", "13px");
            }
            ((HyperLink)e.Item.FindControl("lnkMenu")).ToolTip = ((CJJCH.Model.T_NET_MenuFirst)e.Item.DataItem).MenuName;

            ((HyperLink)e.Item.FindControl("lnkMenu")).Attributes.Add("onclick", "divname('"
                 + ((HyperLink)e.Item.FindControl("lnkMenu")).Text + "','"
                 + lblType1.ClientID.ToString() + "',"
                 + ((CJJCH.Model.T_NET_MenuFirst)e.Item.DataItem).ID + ","
                 + 0 + ","
                 + 0 + ",'"
                 + txtFID.ClientID.ToString() + "','"
                 + txtSID.ClientID.ToString() + "','"
                 + txtTID.ClientID.ToString() + "','"
                 + txtName.ClientID.ToString() + "');");
            Repeater rptSubMenu = (Repeater)e.Item.FindControl("rptSubMenu");
            IList<CJJCH.Model.T_NET_MenuSecond> list = new List<CJJCH.Model.T_NET_MenuSecond>();
            list = bll_second.GetMenuType(0, ((CJJCH.Model.T_NET_MenuFirst)e.Item.DataItem).ID);
            if (list.Count > 0)
            {
                rptSubMenu.DataSource = list;
                rptSubMenu.DataBind();
            }
        }

        protected void rptSubMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                ((HyperLink)e.Item.FindControl("lnkSubMenu")).Text = "|-" + LTP.Common.StringClass.GetENString(((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuName,8);
                if (((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuName.Length > 8)
                {
                    ((HyperLink)e.Item.FindControl("lnkSubMenu")).Style.Add("font-size", "12px");
                }
            }
            if (((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).HaveChild && ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuTypeID != 1 && ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuTypeID != 8)
            {
                ((HyperLink)e.Item.FindControl("lnkSubMenu")).Attributes.Add("onclick", "divname('"
                    + ((HyperLink)e.Item.FindControl("lnkSubMenu")).Text + "','"
                 + lblType1.ClientID.ToString() + "',"
                 + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).FirstID + ","
                 + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID + ","
                 + 0 + ",'"
                 + txtFID.ClientID.ToString() + "','"
                 + txtSID.ClientID.ToString() + "','"
                 + txtTID.ClientID.ToString() + "','"
                 + txtName.ClientID.ToString() + "');");
                Repeater rptTMenu = (Repeater)e.Item.FindControl("rptTMenu");
                IList<CJJCH.Model.T_NET_MenuThird> list = new List<CJJCH.Model.T_NET_MenuThird>();
                list = bll_third.GetThird(((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID, "");
                if (list.Count > 0)
                {
                    if (((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID != 4)
                    {
                        rptTMenu.DataSource = list;
                        rptTMenu.DataBind();
                    }
                }
            }
            else
            {
                ((HyperLink)e.Item.FindControl("lnkSubMenu")).Attributes.Add("onclick", "divname('"
                   + ((HyperLink)e.Item.FindControl("lnkSubMenu")).Text + "','"
                 + lblType1.ClientID.ToString() + "',"
                 + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).FirstID + ","
                 + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID + ","
                 + 0 + ",'"
                 + txtFID.ClientID.ToString() + "','"
                 + txtSID.ClientID.ToString() + "','"
                 + txtTID.ClientID.ToString() + "','"
                 + txtName.ClientID.ToString() + "');");
            }
        }

        protected void rptTMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                ((HyperLink)e.Item.FindControl("lnkTMenu")).Text = "|-" + LTP.Common.StringClass.GetENString(((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).MenuName,6);
                if (((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).MenuName.Length > 8)
                {
                    ((HyperLink)e.Item.FindControl("lnkTMenu")).Style.Add("font-size", "12px");
                }
            }

            ((HyperLink)e.Item.FindControl("lnkTMenu")).Attributes.Add("onclick", "divname('"
                     + ((HyperLink)e.Item.FindControl("lnkTMenu")).Text + "','"
                 + lblType1.ClientID.ToString() + "',"
                 + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).MenuSecond.FirstID + ","
                 + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).SecondID + ","
                 + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).ID + ",'"
                 + txtFID.ClientID.ToString() + "','"
                 + txtSID.ClientID.ToString() + "','"
                 + txtTID.ClientID.ToString() + "','"
                 + txtName.ClientID.ToString() + "');");
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            InitMenu();
            if (txtSearch.Text == "请输入文章关键字")
            {
                txtSearch.Text = "";
            }
            if (txtSearch.Text == "")
            {
                this.Keyword = "";
            }
            if (txtFID.Text != "" && LTP.Common.CheckInput.CheckDigit(txtFID.Text))
            {
                this.FirstId = Convert.ToInt32(txtFID.Text);
            }
            if (txtSID.Text != "" && LTP.Common.CheckInput.CheckDigit(txtSID.Text))
            {
                this.SecondId = Convert.ToInt32(txtSID.Text);
            }
            if (txtTID.Text != "" && LTP.Common.CheckInput.CheckDigit(txtTID.Text))
            {
                ThirdId = Convert.ToInt32(txtTID.Text);
            }
            string Typename = "";
            if (txtName.Text != "")
            {
                Typename = txtName.Text;
            }
            else if ((lblType1.Text) != "请选择文章类型")
            {
                Typename = lblType1.Text;
            }
            if (SecondId == 0)
            {

                switch (FirstId)
                {
                    case 1:
                        Response.Redirect("~/ListPage.aspx?firstid=" + FirstId.ToString() + "&typename=" + Typename
                           );
                        break;
                    case 2:
                        Response.Redirect("~/ListPage.aspx?firstid=" + FirstId.ToString() + "&typename=" + Typename
                           );
                        break;
                    case 3:
                        Response.Redirect("~/ListPage.aspx?firstid=" + FirstId.ToString() + "&typename=" + Typename
                           );
                        break;
                    case 4:
                        Response.Redirect("~/ListPage.aspx?firstid=" + FirstId.ToString() + "&typename=" + Typename
                           );
                        break;
                    case 5:
                        Response.Redirect("~/ListPage.aspx?firstid=" + FirstId.ToString() + "&typename=" + Typename
                           );
                        break;
                    case 6:
                        Response.Redirect("~/NotePage.aspx?firstid=" + FirstId.ToString() + "&typename=" + Typename
                           );
                        break;
                    case 7:
                        Response.Redirect("~/ListPage.aspx?firstid=" + FirstId.ToString() + "&typename=" + Typename
                           );
                        break;
                    case 8:
                        Response.Redirect("~/NotePage.aspx?firstid=" + FirstId.ToString() + "&typename=" + Typename
                           );
                        break;
                    default:
                        break;
                }
            }
            else
            {
                switch (FirstId)
                {
                    case 1:
                        Response.Redirect("~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + SecondId.ToString() + "&thirdid=" + ThirdId.ToString() + "&keyword=" + txtSearch.Text + "&typename=" + Typename
                           );
                        break;
                    case 2:
                        if (SecondId != 4)
                        {
                            Response.Redirect("~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + SecondId.ToString() + "&thirdid=" + ThirdId.ToString() + "&keyword=" + txtSearch.Text + "&typename=" + Typename
                               );
                        }
                        else
                        {
                            Response.Redirect("~/ApplicationProcedures.aspx?firstid=" + FirstId.ToString() + "&secondid=" + SecondId.ToString() + "&thirdid=" + ThirdId.ToString() + "&keyword=" + txtSearch.Text + "&typename=" + Typename
                             );
                        }
                        break;
                    case 3:
                        if (SecondId != 8)
                        {
                            Response.Redirect("~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + SecondId.ToString() + "&thirdid=" + ThirdId.ToString() + "&keyword=" + txtSearch.Text + "&typename=" + Typename
                               );
                        }
                        else
                        {
                            Response.Redirect("~/OnLineRegis.aspx?firstid=" + FirstId.ToString() + "&secondid=" + SecondId.ToString() + "&thirdid=" + ThirdId.ToString() + "&keyword=" + txtSearch.Text + "&typename=" + Typename
                                                         );
                        }
                        break;
                    case 4:
                        if (SecondId != 12)
                        {
                            Response.Redirect("~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + SecondId.ToString() + "&thirdid=" + ThirdId.ToString() + "&keyword=" + txtSearch.Text + "&typename=" + Typename
                               );
                        }
                        else 
                        {
                            Response.Redirect("~/ExpertAppraisal.aspx?firstid=" + FirstId.ToString() + "&secondid=" + SecondId.ToString() + "&thirdid=" + ThirdId.ToString() + "&keyword=" + txtSearch.Text + "&typename=" + Typename
                               );
                            
                        }
                        break;
                    case 5:
                        Response.Redirect("~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + SecondId.ToString() + "&thirdid=" + ThirdId.ToString() + "&keyword=" + txtSearch.Text + "&typename=" + Typename
                           );
                        break;
                    case 6:
                        Response.Redirect("~/NotePage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + SecondId.ToString() + "&thirdid=" + ThirdId.ToString() + "&keyword=" + txtSearch.Text + "&typename=" + Typename
                           );
                        break;
                    case 7:
                        Response.Redirect("~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + SecondId.ToString() + "&thirdid=" + ThirdId.ToString() + "&keyword=" + txtSearch.Text + "&typename=" + Typename);
                        break;
                    case 8:
                        Response.Redirect("~/NotePage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + SecondId.ToString() + "&thirdid=" + ThirdId.ToString() + "&keyword=" + txtSearch.Text + "&typename=" + Typename);
                        break;
                    default:
                        break;
                }
            }
        }
    }

}
